//
//  DeviceInfo.swift
//  DemoNavBar
//
//  Created by YangHuan on 2019/12/13.
//  Copyright © 2019 YangHuan. All rights reserved.
//


import DeviceKit

public let kFont9: UIFont = autoFont(9)
public let kFont10: UIFont = autoFont(10)
public let kFont11: UIFont = autoFont(11)
public let kFont12: UIFont = autoFont(12)
public let kFont13: UIFont = autoFont(13)
public let kFont14: UIFont = autoFont(14)
public let kFont15: UIFont = autoFont(15)
public let kFont16: UIFont = autoFont(16)
public let kFont17: UIFont = autoFont(17)
public let kFont18: UIFont = autoFont(18)
public let kFont20: UIFont = autoFont(20)
public let kFont21: UIFont = autoFont(21)
public let kFont22: UIFont = autoFont(22)
public let kFont24: UIFont = autoFont(24)
public let kbFont34: UIFont = autoBoldFont(34)
public let kbFont14: UIFont = autoBoldFont(14)
public let kbFont18: UIFont = autoBoldFont(18)
public let kTFTintColor = UIColor.lightGray

public func autoWidth(_ width: CGFloat) -> CGFloat {
    return width * widthScale
}
public func autoHeight(_ height: CGFloat) -> CGFloat {
    return height * heightScale
}

/// 宽度缩放比例
private let widthScale: CGFloat = {
    if DeviceOption.currentDevice == .iphoneMini  {
        return 320 / 375.0
    }
    if DeviceOption.currentDevice == .iphonePlus  {
        return 414 / 375.0
    }
    if DeviceOption.currentDevice == .iphoneX  {
        return 375 / 375.0
    }
    
    return 1.0
}()

/// 高度缩放比例
private let heightScale: CGFloat = {
    if DeviceOption.currentDevice == .iphoneMini  {
        return 568 / 667.0
    }
    if DeviceOption.currentDevice == .iphonePlus  {
        return 736 / 667.0
    }
    if DeviceOption.currentDevice == .iphoneX  {
        return 812 / 667.0
    }
    return 1.0
}()

func nFont(_ fontSize: Double) -> UIFont {
    return UIFont.systemFont(ofSize: CGFloat(fontSize))
}

func autoFont(_ fontSize: Double) -> UIFont {
    if DeviceOption.currentDevice == .iphoneMini {
        return UIFont.systemFont(ofSize: CGFloat(fontSize - 1))
    } else if DeviceOption.currentDevice == .iphonePlus {
        return UIFont.systemFont(ofSize: CGFloat(fontSize + 1))
    } else {
        return UIFont.systemFont(ofSize: CGFloat(fontSize))
    }
}

func autoBoldFont(_ fontSize: Double) -> UIFont {
    if DeviceOption.currentDevice == .iphoneMini {
        return UIFont.boldSystemFont(ofSize: CGFloat(fontSize - 1))
    } else if DeviceOption.currentDevice == .iphonePlus {
        return UIFont.boldSystemFont(ofSize: CGFloat(fontSize + 1))
    } else {
        return UIFont.boldSystemFont(ofSize: CGFloat(fontSize))
    }
}


    



private let miniDevices: [Device] = [.iPhone4, .iPhone4s, .simulator(.iPhone4), .simulator(.iPhone4s), .iPhone5, .iPhone5s, .iPhone5c, .iPhoneSE, .simulator(.iPhone5s), .simulator(.iPhone5), .simulator(.iPhone5c), .simulator(.iPhoneSE)]
private let normalDevice: [Device] = [.iPhone6, .iPhone6s, .iPhone7, .iPhone8, .simulator(.iPhone6), .simulator(.iPhone6), .simulator(.iPhone6s), .simulator(.iPhone7), .simulator(.iPhone8)]

private let plusDevice: [Device] = [.iPhone6Plus, .iPhone6sPlus, .iPhone7Plus, .iPhone8Plus, .simulator(.iPhone6Plus), .simulator(.iPhone6sPlus), .simulator(.iPhone7Plus), .simulator(.iPhone8Plus)]

private let iPhoneXDevice: [Device] = [.iPhoneX, .simulator(.iPhoneX), .iPhoneXs, .simulator(.iPhoneXs), .iPhoneXr, .simulator(.iPhoneXr), .iPhoneXsMax, .simulator(.iPhoneXsMax)]



/// 设备类型
enum DeviceOption: String {
    // mini
    case iphoneMini = "iphoneMini"
    // iphone6
    case iphoneNormal = "iphoneNormal"
    // plus
    case iphonePlus = "iphonePlus"
    // iphoneX
    case iphoneX = "iphoneX"
    
    static let currentDevice: DeviceOption = {
        
        let device = Device()
        if device.isOneOf(miniDevices) {
            return DeviceOption.iphoneMini
        }
        if device.isOneOf(normalDevice) {
            return DeviceOption.iphoneNormal
        }
        if device.isOneOf(plusDevice) {
            return DeviceOption.iphonePlus
        }
        if device.isOneOf(iPhoneXDevice) {
            return DeviceOption.iphoneX
        }
        return DeviceOption.iphoneNormal
    }()
}

public let isIphoeX: Bool = {
    return DeviceOption.currentDevice == .iphoneX
}()


